package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.HighLeverDto;
import com.hualude.roadsign.dto.DTRequestDto;
import com.hualude.roadsign.dto.DTResponseDto;
import com.hualude.roadsign.dto.JsonMsgDto;
import com.hualude.roadsign.service.HighLeverManageService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by xu_jiaHui on 2018/3/24.
 */
@Controller
@RequestMapping("/rds_HighLeverManage")
public class HighLeverManageController {
    @Resource
    private HighLeverManageService highLeverService;

    @RequestMapping("/getHighLever4DT")
    @ResponseBody
    public DTResponseDto getHighLever4DT(DTRequestDto dtRequestDto,
                                         String actorIds,
                                         Integer orgId,
                                         Boolean audit,
                                         String startRoad,
                                         String endRoad,
                                         String roadName,
                                         Integer alarmBinding) throws Exception {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = highLeverService.getHighLever4DT(
                    dtRequestDto, actorIds, orgId, audit, startRoad, endRoad, roadName,alarmBinding);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping("/deleteHighLever")
    @ResponseBody
    public JsonMsgDto deleteHighLever(String highLeverIds) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(highLeverService.deleteHighLever(highLeverIds));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/addHighLever")
    @ResponseBody
    public JsonMsgDto addHighLever(HighLeverDto highLeverDto) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(highLeverService.addHighLever(highLeverDto));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/updateHighLever")
    @ResponseBody
    public JsonMsgDto updateHighLever(HighLeverDto highLeverDto) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(highLeverService.updateHighLever(highLeverDto));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getStartRoadByRoadName")
    @ResponseBody
    public JsonMsgDto getStartRoadByRoadName(String roadName, String actorIds, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(highLeverService.getStartRoadByRoadName(roadName, actorIds, orgId));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getEndRoadByStartRoad")
    @ResponseBody
    public JsonMsgDto getEndRoadByStartRoad(String city, String highLeverRoadName, String startRoad, String actorIds, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(highLeverService.getEndRoadByStartRoad(city, highLeverRoadName, startRoad, actorIds, orgId));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getHighLever4APP")
    @ResponseBody
    public JsonMsgDto getHighLever4APP(String actorIds,
                                       Integer orgId,
                                       Integer mCount,
                                       Integer mSize,
                                       String city,
                                       String startRoad,
                                       String endRoad,
                                       String roadName,
                                       String alarmType) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(highLeverService.getHighLever4APP(
                    actorIds, orgId, mCount, mSize, city, startRoad, endRoad, roadName, alarmType));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getHighLeverById")
    @ResponseBody
    public JsonMsgDto getHighLeverById(Integer highLeverId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(highLeverService.getHighLeverById(highLeverId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getCity4HighLever4App")
    @ResponseBody
    public JsonMsgDto getCity4HighLever4App(String actorIds, Integer orgId, Integer mCount, Integer mSize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(highLeverService.getCity4HighLever4App(actorIds, orgId, mCount, mSize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getRoadName4HighLeverByCity")
    @ResponseBody
    public JsonMsgDto getRoadName4HighLeverByCity(String actorIds, Integer orgId, String city, Integer mCount, Integer mSize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(highLeverService.getRoadName4HighLeverByCity(actorIds, orgId, city, mCount, mSize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getStartRoadByRoadName4App")
    @ResponseBody
    public JsonMsgDto getStartRoadByRoadName4App(String city, String roadName, String actorIds, Integer orgId, Integer mCount, Integer mSize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(highLeverService.getStartRoadByRoadName4App(city, roadName, actorIds, orgId, mCount, mSize));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getEndRoadByStartRoad4App")
    @ResponseBody
    public JsonMsgDto getEndRoadByStartRoad4App(String city, String highLeverRoadName, String startRoad, String actorIds, Integer orgId, Integer mCount, Integer mSize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(highLeverService.getEndRoadByStartRoad4App(city, highLeverRoadName, startRoad, actorIds, orgId, mCount, mSize));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getHighLever4Map4App")
    @ResponseBody
    public JsonMsgDto getHighLever4Map4App(Integer orgId,
                                           String actorIds,
                                           double neLongitude,
                                           double neLatitude,
                                           double swLongitude,
                                           double swLatitude) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(highLeverService.getHighLever4Map4App
                    (orgId, actorIds, neLongitude, neLatitude, swLongitude, swLatitude));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/auditHighLever")
    @ResponseBody
    public JsonMsgDto auditHighLever(String highLeverIds) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(highLeverService.auditHighLever(highLeverIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/setUpPatrolRecord")
    @ResponseBody
    public JsonMsgDto setUpPatrolRecord(Integer highLeverId, String highLeverPatrolTime, String highLeverPatrolContent, Integer highLeverModifierId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(highLeverService.setUpPatrolRecord(highLeverId, highLeverPatrolTime, highLeverPatrolContent, highLeverModifierId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @ResponseBody
    @RequestMapping("/bindingDevice")
    public JsonMsgDto bindingDevice(String deviceId,Integer highLeverId){
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try{
            jsonMsgDto.setJsonData(highLeverService.bindingDevice(deviceId,highLeverId));
            jsonMsgDto.setIsSuccess(true);
        }catch (Exception e){
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @ResponseBody
    @RequestMapping("/unbindingDevice")
    public JsonMsgDto unbindingDevice(String deviceId,Integer highLeverId){
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try{
            jsonMsgDto.setJsonData(highLeverService.unbindingDevice(deviceId,highLeverId));
            jsonMsgDto.setIsSuccess(true);
        }catch (Exception e){
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @ResponseBody
    @RequestMapping("showAlarmHistory")
    public DTResponseDto showAlarmHistory(DTRequestDto dtRequestDto,String deviceId,Integer deviceType){
        DTResponseDto dtResponseDto=null;
        try{
            dtResponseDto=highLeverService.showAlarmHistory(dtRequestDto,deviceId,deviceType);
        }catch (Exception e){
            e.printStackTrace();
        }
        return dtResponseDto;
    }

}

